import java.awt.Component;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JToolBar;

import org.jhotdraw.application.*;
import org.jhotdraw.contrib.ComponentFigure;
import org.jhotdraw.figures.RectangleFigure;
import org.jhotdraw.framework.Drawing;
import org.jhotdraw.framework.DrawingView;
import org.jhotdraw.standard.CreationTool;
import org.jhotdraw.standard.StandardDrawingView;

public class GUIGenApp extends DrawApplication {
	DrawingCanvas newDrawingView;
	


	public GUIGenApp() {
		super("Java GUI Generator");

	}

	public GUIGenApp(String title) {
		super(title);
	}

	// I have overwritten this method by changing the newDrawingView so
	// that it points to our DrawingCanvas class. Theres no polymorphic call
	// happening now but I will switch that soon so theres looser coupling. - JD
	protected DrawingView createDrawingView(Drawing newDrawing) {
		Dimension d = getDrawingViewSize();
	    newDrawingView = new DrawingCanvas(this, d.width, d.height);
		newDrawingView.setDrawing(newDrawing);
		// notify listeners about created view when the view is added to the desktop
		//fireViewCreatedEvent(newDrawingView);
		return newDrawingView;
	}
	protected void createTools(JToolBar palette) {
		super.createTools(palette);
		
		CreationTool tool = new CreationTool(this, new RectangleFigure());
		palette.add(createToolButton(IMAGES+"RECT","RectangleFigure", tool));
		
		Component button = new JButton("Hello World");
		tool = new CreationTool(this, new ComponentFigure(button));
		palette.add(createToolButton(IMAGES + "RECT", "Component Tool", tool));
		//palette.add(testButton);
	}
	public void toolDone() {
		System.out.println("ToolDone");
		newDrawingView.getGUICode();
		if (fDefaultToolButton != null) {
			setTool(fDefaultToolButton.tool(), fDefaultToolButton.name());
			setSelected(fDefaultToolButton);
		}
	}
	
	public static void main(String[] args) {
		DrawApplication window = new GUIGenApp();
		window.open();

	}
	
	}



